package me.shiqiang.im.run;

import me.shiqiang.im.service.RouterServerNodeClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;


/**
 * Created by maliangxue on 2018/4/15.
 */
@Component
public class ServerCommand implements CommandLineRunner {

    @Value("${im.router.server.ip}")
    String serverIp;

    @Value("${connect.port}")
    String port;

    @Autowired
    RouterServerNodeClient client;

    @Override
    public void run(String... strings) throws Exception {
        if(StringUtils.isNotBlank(serverIp)&& StringUtils.isNotBlank(port)){
            client.registerRouterIp(serverIp.replaceAll("\\.","_")+"@"+port);
        }
    }
}
